import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;


public class BowlingTest
{
	private BowlingGame bg;
	@Before
	public void SetUp()
	{
		bg=new BowlingGame();
	}
	@Test
	public void ShouldBeGutterGame()
	{
		for(int x=0;x<20;x++)
		{
			bg.bowl(0);
		}
		Assert.assertEquals(0, bg.getScore());
	}
	@Test
	public void ShouldBeAllOnes()
	{
		for(int x=0;x<20;x++)
		{
			bg.bowl(1);
		}
		Assert.assertEquals(20, bg.getScore());
	}
	@Test
	public void ShouldBeSimpleSpare()
	{
		bg.bowl(5);
		bg.bowl(5);
		bg.bowl(5);
		repeat(17,0);
		Assert.assertEquals(20, bg.getScore());
	}
	@Test
	public void ShouldBeSimpleSpare2()
	{
		bg.bowl(3);
		bg.bowl(7);
		bg.bowl(3);
		repeat(17,0);
		Assert.assertEquals(16, bg.getScore());
	}
	@Test
	public void ShouldBeSimpleSpare3()
	{
		bg.bowl(2);
		bg.bowl(8);
		bg.bowl(3);
		bg.bowl(7);
		bg.bowl(4);
		bg.bowl(5);
		repeat(14,0);
		Assert.assertEquals(36, bg.getScore());
	}
	@Test
	public void ShouldBeSimpleStrike1()
	{
		bg.bowl(10);
		bg.bowl(5);
		bg.bowl(2);
		repeat(16,0);
		Assert.assertEquals(24, bg.getScore());
	}
	@Test
	public void ShouldBePerfectScore()
	{
		repeat(12,10);
		Assert.assertEquals(300, bg.getScore());
	}
	@Test
	public void ShouldBeScoreAfter3Ones()
	{
		repeat(3,1);
		Assert.assertEquals(2, bg.getScore());
	}
	@Test
	public void ShouldBeScoreMidgame()
	{
		repeat(6,10);
		Assert.assertEquals(120, bg.getScore());
	}
	public void repeat(int times, int pins)
	{
		for(int x=0;x<times;x++)
		{
			bg.bowl(pins);
		}
	}
}
